/**
 * Created by Administrator on 2017/5/16 0016.
 */
define(["jquery","template","scprit/department/view/template/growingDevelopmentDetails-tpl.js"],function($,template,tpl){
    var question={};
    var inTable = function (data) {
        return template("growthList", data);
    };
    var inTable2 = function (data) {
        return template("userDetail", data);
    };
    var inTable3 = function (data) {
        return template("trendsBox-tpl", data);
    };
    var inTable4 = function (data) {
        return template("printUserDetail-tpl", data);
    };
    question.historyListInit = function (options) {
        $(options.id).html(tpl.init());
        var html = inTable(options);
        $(options.id).html(html);
    };
    question.userInfoInit = function (options) {
        $(options.id).html(tpl.init2());
        console.log(options)
        var html = inTable2(options.value);
        $(options.id).html(html);
    };
    question.trendsBoxInit=function(options){
        $(options.id).html(tpl.init3());
        var html = inTable3(options.value);
        $(options.id).html(html);
    }
    question.printUserInfoInit = function (options) {
        $(options.id).html(tpl.init4());
        var html = inTable4(options.value);
        $(options.id).html(html);
    };
    question.loadingInit = function (options) {
        $(options.id).html(tpl.init5());
        $(options.id).html(template("tpl_loading"));
    };
    //姓名截取八个字
    question.nameLens = function(name){
        if(name.length>8){
            var username=name.substring(0,8);
        }else{
            username=name;
        }
        return username;
    }
    //计算天数差的函数，通用 ：
    question.DateDiff=function(sDate1,  sDate2){
        var  aDate,  oDate1,  oDate2,  iDays;
        aDate  =  sDate1.split("-");
        oDate1  =  new  Date(parseFloat(aDate[0]),parseFloat(aDate[1])-1,parseFloat(aDate[2]));    //创建时间；
        aDate  =  sDate2.split("-");
        oDate2  =  new  Date(parseFloat(aDate[0]),parseFloat(aDate[1])-1,parseFloat(aDate[2]));    //创建时间；
        iDays  =  parseInt(Math.abs(oDate1  -  oDate2)  /  1000  /  60  /  60  /24);    //把相差的毫秒数转换为天数
        return  iDays
    }
    //实际年龄：
    question.getAge=function(day){
        if (day == 0) return '0天' 

        var y = parseInt(day/365)==0 ? "":parseInt(day/365);
        var m = parseInt(day%365/30.4)==0 ? "":parseInt(day%365/30.4);
        var w = parseInt(day%365%30.4/7)==0 ? '':parseInt(day%365%30.4/7);
        var d = parseInt(day%365%30.4%7)==0 ? '':parseInt(day%365%30.4%7);
        var age;
        if(y){
            age = y + "岁" + (m >= 1 ? m + "月龄" : "");
        }else{
            if( m >= 3 ){
                age = m + "月龄" + (parseInt(day%365%30.4) > 0 ? parseInt(day%365%30.4) + '天' : '天');
            }else{
                var days = day;
                age = (parseInt(days/7) > 0 ? parseInt(days/7)+"周" : "") + (parseInt(days%7) > 0 ? parseInt(days%7) + '天' : '');
            }
        }
        return age
    }
    //纠正年龄：
    question.age=function(acturalDay,pregnance){
        var day,age2;
        if(parseFloat(pregnance) < 37*7){
            var difD=40*7-parseFloat(pregnance); //判断与预产期差了多少天；
            day=acturalDay-difD;
            if(day>0){
                age2=this.getAge(day);
            }else{
                age2=day+"天";
            }
        }else{
            day=acturalDay;
            age2=this.getAge(day);
        }
        return age2;
    }
    //孕周
    question.pregnancyDay=function(day){
        var w=parseInt(day/7);
        var d=day%7;
        return w+"周"+d+"天"
    }
    question.toPregnancyDay=function(day){
       var days=day*7;
        var w=parseInt(days/7);
        var d=Math.round(days%7);
        return w+"周"+d+"天"
    }
    question.toWeekDay=function(week){
        var w=parseInt(week);//获得周
        var d=Math.round((week-w)*7);//获得天
        var age;
        w? age=w+"周"+(d?(d+"天"):''):age=d+"天";
        return age
    };
    //月：
    question.toMonthDay=function (month){
        var m=parseInt(month);//获得月份；
        var w=parseInt((month-m)*30.4/7);//获得周
        var d=Math.round((month-m)*30.4%7);//获得天
        var age;
        m? age=m+"月"+(w? w+"周":"")+(d? d+"天":""):age=(w? w+"周":"")+(d? d+"天":"");
        return age
    }
    //岁：
    question.toYearDay=function(year){
        var y=parseInt(year);//获得年份；
        var m=parseInt((year-y)*365/30.4);//获得月份；
        var w=parseInt(((year-y)*365%30.4)/7);//获得周
        var d=Math.round(((year-y)*365/30.4)%7);//获得天
        var age;
        y?age=y+"岁"+(m? m+"月":"")+(w? w+"周":"")+(d?d+"天":""):age=(m?m+"月":"")+(w? w+"周":"")+(d?d+"天":"");
        return age
    };
    question.babyAgeDeal=function(res,age){
        var babyAge;
        if(res.timeUnit=="周"){
            babyAge=this.toWeekDay(age);
        }
        if(res.timeUnit=="月"){
            babyAge=this.toMonthDay(age);
        }
        if(res.timeUnit=="年"){
            babyAge=this.toYearDay(age);
        }
        return babyAge;
    };
    //曲线数据处理：
    question.dataDo=function(data,max,min,name,color){
        var lens=data.length;
        var res=[];
        min=Number(min);
        len=(max-min)/lens;
        res[0]=[min,data[0]];
        for(i= 0;i<lens;i++){
            if(i==lens-1){
                var lastData={
                    value: [len*(i+1)+min,data[i]],
                    label : {
                        normal:{
                            show: true,
                            position: "insideBottomLeft",
                            textStyle : {
                                color:color,
                                fontSize:"8"
                            },
                            formatter:name
                        }
                    },
                };
                res.push(lastData);
            }else{
                res[i+1]=[len*(i+1)+min,data[i]];
            }
        }
        return res;
    };
    //儿童传入记录值数据处理：
    question.growthRecordDeal=function(data){
        var type=data.type;
        var sexColor;
        var color=["#0596d5","#e47db2","#ff8400"];//0,男；1，女；3，橙色
        var initArr={
            "history":[],
            'nowFlag':[]
        };
        var growthRecordVal=data.growthrecord;
        for(var i=0;i<growthRecordVal.length;i++){
            if(growthRecordVal[i].result) {
                var growthResult = JSON.parse(growthRecordVal[i].result);
                var result, first, last;
                if (data.scoreType == "01") {
                    result = growthResult[0].percentileRange;
                   if(data.curveType == "02"){
                       if (result.indexOf("~") != "-1") {
                           data.sex == "男" ? sexColor = color[0]:sexColor = color[1];
                       }else{
                           sexColor = color[2];
                       }
                   }else{
                       if (result.indexOf("~") != "-1") {
                           first = parseFloat(result.substring(0, result.indexOf("~") - 1));
                           last = parseFloat(result.substring(result.indexOf("~") + 1, result.length - 1));
                           if (type == "weight" || type == "wl") {
                               if (!(first >= 25 && last <= 75)) {
                                   sexColor = color[2];
                               } else {
                                   if (data.sex == "男") {
                                       sexColor = color[0];
                                   } else {
                                       sexColor = color[1];
                                   }
                               }
                           } else if (type == "height" || type == "head") {
                               if (first < 25) {
                                   sexColor = color[2];
                               } else {
                                   data.sex == "男" ? sexColor = color[0]:sexColor = color[1];
                               }
                           }
                       } else {
                           if (result.indexOf("<") != "-1") {
                               sexColor = color[2];
                           } else if (result.indexOf(">") != "-1") {
                               if (type == "weight" || type == "wl") {
                                   sexColor = color[2];
                               } else if (type == "height" || type == "head") {
                                   data.sex == "男" ? sexColor = color[0]:sexColor = color[1];
                               }
                           }
                       }
                   }
                } else {
                    result = growthResult[0].zcorerange;
                    if (result.indexOf("~") != "-1") {
                        first = parseFloat(result.substring(0, result.indexOf("~")));
                        last = parseFloat(result.substring(result.indexOf("~") + 1, result.length));
                        if(first>= -2 && last <= 2){
                            data.sex == "男" ? sexColor = color[0]:sexColor = color[1];
                        }else{
                            sexColor = color[2];
                        }
                    } else {
                        if (result.indexOf("<") != "-1" || result.indexOf(">") != "-1") {
                            sexColor = color[2];
                        }
                    }
                }
            }
            var recentGrowthRecord2={
                value: [growthRecordVal[i].xDate,growthRecordVal[i].yDate],
                itemStyle: {
                    normal:{
                        color:sexColor
                    },
                    emphasis: {
                        color: sexColor
                    }
                }
            };
            if(growthRecordVal[i].flag=="1"){
                initArr.nowFlag = [growthRecordVal[i].xDate,growthRecordVal[i].yDate,sexColor];
            }
            initArr.history.push(recentGrowthRecord2);
        }
        return initArr;
    };
    //数据格式处理：
    question.dataDo2=function(data){
        var obj={};
        obj.xMax=data.xMax;
        obj.xMin=data.xMin;
        obj.yMax=data.yMax;
        obj.yMin=data.yMin;
        obj.scoreType=data.scoreType;
        if((obj.yMax-obj.yMin)>60){
            obj.interval=5;
        }else if((obj.yMax-obj.yMin)<=25){
            obj.interval=1;
        }else{
            obj.interval=2;
        }
        var name;
        if(obj.scoreType == "01"){
            name=["50%","25%","75%","10%","90%","3%","97%"];
        }else{
            name=["0","-1","1","-2","2","-3","3"];
        }
        var colors = ['#00612d','#ffb13d','#e41836','#252122'];//0--SD0,1--SD1,SD1neg,2--SD2,SD2neg,3--SD3,SD3neg
        if(data.SD0){
            obj.sd0={
                "num":0,
                "name":name[0],
                "sd0":this.dataDo(data.SD0, data.xMax, data.xMin,name[0],colors[0])
            };
        }
        if(data.SD1){
            obj.sd1={
                "num":1,
                "name":name[2],
                "sd1":this.dataDo(data.SD1, data.xMax, data.xMin,name[2],colors[1])
            };
        }
        if(data.SD1eng){
            obj.sd1neg={
                "num":1,
                "name":name[1],
                "sd1neg":this.dataDo(data.SD1eng, data.xMax, data.xMin,name[1],colors[1])
            };
        }
        if(data.SD2){
            obj.sd2={
               "num":2,
               "name":name[4],
               "sd2":this.dataDo(data.SD2, data.xMax, data.xMin,name[4],colors[2])
            };
       }
        if(data.SD2eng){
            obj.sd2neg={
                "num":2,
                "name":name[3],
                "sd2neg":this.dataDo(data.SD2eng, data.xMax, data.xMin,name[3],colors[2])
            };
        }
        if(data.SD3){
            obj.sd3={
                "num":3,
                "name":name[6],
                "sd3":this.dataDo(data.SD3, data.xMax, data.xMin,name[6],colors[3])
            };
        }
        if(data.SD3eng){
           obj.sd3neg={
               "num":3,
               "name":name[5],
               "sd3neg":this.dataDo(data.SD3eng, data.xMax, data.xMin,name[5],colors[3])
           };
       }

        //儿童记录：
        var backData=this.growthRecordDeal(data);
        obj.grownRecord=backData.history;
        obj.grownNowRecord=backData.nowFlag;
        if(data.timeUnit=="周"){
            obj.xName="周龄（0-26周)";
        }else if(data.timeUnit=="月"){
            obj.xName="月龄（0-24月)";
        }else if(data.timeUnit=="年"){
            obj.xName="年龄（0-5岁)";
        }
        obj.timeUnit=data.timeUnit;
        return obj;
    };

    //患者信息详情数据处理：
    question.userInfoDeal=function(data){
        var obj = {};
        /**
         * 常用属性
         */
        obj.userName    = data.userName;
        obj.gender      = data.gender == "F" ? "女" : "男";
        obj.weekAge     = data.weekAge;
        obj.doctorName  = data.doctorName;
        obj.createTime  = data.createTime;
        /**
         * 判断出生日期显示值
         */
        if (data.birthday) {
            var diff = this.DateDiff(data.testTime, data.birthday);
            obj.correctAge=this.age(diff, data.pregnancyDay);
            obj.acturalAge=this.getAge(diff);
        } else {
            obj.nowAge = "未知";
            obj.acturalAge = "未知";
        }
        /**
         * 按钮类型
         * @param 01 百分位图
         * @param 02 Z评分图
         */
         obj.curveType  = data.scoreType;
        /**
         * 曲线类型
         * @param 01 who   
         * @param 02 feton 
         */
        obj.curveType2 = data.curveType;
        /**
         * 当前图的分类  
         * @param 百分位
         * @param Z评分
         */
        obj.curveType3 = '';
        /**
         * 年龄类型
         * @param 01 纠正年龄 
         * @param 02 实际年龄
         */
        obj.ageType    = data.ageType;
        /**
         *  孕周、身高、体重、头围
         */
        obj.pregnancyDayNum = data.pregnancyDay;
        obj.pregnancyDay = this.pregnancyDay(data.pregnancyDay); 
        obj.height     = data.hight ? data.hight : '无';          
        obj.weight     = data.weight ? data.weight : '无';          
        obj.headCircumference = data.headCircumference ? data.headCircumference : '无';
        /**
         * 纠正年龄下 获取结论 实际年龄下 获取结论
         * @param ageType   01 纠正年龄 || 实际年龄
         * @param curveType 01 百分位图
         * @param curveType 02 Z评分图
         */
        var heightSumary = data.hightSummary
        var weightSumary = data.weightSummary
        var headSumary = data.headSummary
        if (obj.curveType == '01') {
            obj.heightPercent = getSingleResult(obj.height, heightSumary, '百分位(%)');
            obj.weightPercent = getSingleResult(obj.weight, weightSumary, '百分位(%)');
            obj.headPercent = getSingleResult(obj.headCircumference, headSumary, '百分位(%)');
            obj.curveType3 = '百分位(%)';
        } else if (obj.curveType == '02') {
            obj.heightPercent = getSingleResult(obj.height, heightSumary, 'Z评分');
            obj.weightPercent = getSingleResult(obj.weight, weightSumary, 'Z评分');
            obj.headPercent = getSingleResult(obj.headCircumference, headSumary, 'Z评分');
            obj.curveType3 = 'Z评分';
        }

        
        /**
         * obj 对象写入基础检测值  减少代码行数 120 行
         * @param {*} data 
         * @param {*} paramName 
         * @param {*} type 
         * @returns 后台得值是错误的需要重写判断
         */
        // function setObjParams(data, paramName, type) {
        //     if (!data) return;
        //     var result = JSON.parse(data);
        //     try { obj.weightPercent = result.weightResult[0][paramName]; } catch(err) { obj.weightPercent = '无'; }
        //     try { obj.heightPercent = result.heightResult[0][paramName]; } catch(err) { obj.heightPercent = '无'; }
        //     try { obj.headPercent = result.headtResult[0][paramName]; } catch(err) { obj.headPercent = '无'; }
        //     obj.curveType3 = type;
        // }
        /**
         * 开始判断 身高 显示的结论
         */
        
        getResult(obj.height, heightSumary, 'height', [
            '上+', '上', '上-', '中+', '中', '中-', '下', '迟缓'
        ]);

        /**
         * 开始判断 体重 显示的结论
         */
        getResult(obj.weight, weightSumary, 'weight', [
            '上+', '上', '上-', '中+', '中', '中-', '下', '迟滞'
        ]);
        

        /**
         * 开始判断 头围 显示的结论
         */
        getResult(obj.headCircumference, headSumary, 'head', [
            '偏大', '上', '上-', '中+', '中', '中-', '下', '偏小'
        ]);
        

        /**
         * 开始判断 整体发育情况 显示的结论
         * @param weightForLength 小于 2 岁时有这个属性
         */
        var weightForLength = data.weightForLength;
        getResult(obj.weight, weightForLength, 'wL', [
            obj.curveType == '01' ? '> 97%' : '>3',
            obj.curveType == '01' ? '90% ~ 97%' : '2 ~ 3',
            obj.curveType == '01' ? '75% ~ 90%' : '1 ~ 2',
            obj.curveType == '01' ? '50% ~ 75%' : '0 ~ 1',
            obj.curveType == '01' ? '25% ~ 50%' : '-1 ~ 0',
            obj.curveType == '01' ? '10% ~ 25%' : '-2 ~ -1',
            obj.curveType == '01' ? '3% ~ 10%' : '-3 ~ -2',
            obj.curveType == '01' ? '< 3%' : '< -3'
        ]);
        /**
         * 开始判断 整体发育情况 显示的结论
         * @param ageForWtMap 大于 2 岁时有这个属性
         */
        var bmiSumary = data.ageForWtMap;
        if (bmiSumary) {    // 单独提出是因为 不走 else 
            var bmi= obj.weight / (obj.height / 100) / (obj.height / 100);
            getResult(bmi, bmiSumary, 'wL', [
                obj.curveType == '01' ? '> 97%' : '>3',
                obj.curveType == '01' ? '90% ~ 97%' : '2 ~ 3',
                obj.curveType == '01' ? '75% ~ 90%' : '1 ~ 2',
                obj.curveType == '01' ? '50% ~ 75%' : '0 ~ 1',
                obj.curveType == '01' ? '25% ~ 50%' : '-1 ~ 1',
                obj.curveType == '01' ? '10% ~ 25%' : '-2 ~ -1',
                obj.curveType == '01' ? '3% ~ 10%' : '-3 ~ -2',
                obj.curveType == '01' ? '< 3%' : '< -3'
            ]);
        }
        /**
         * 
         * @param {*} val 
         * @param {*} limits 
         * @param {*} key 
         * @param {*} tests 
         */
        function getResult(val, limits, key, tests) {
			
            if (!$.isEmptyObject(limits) && val != '无') {
                // 97 %
                (val > limits.SD3) && setParams(key, tests[0], 1); 
                // 97% - 90%  
                (val <= limits.SD3) && (val > limits.SD2) && setParams(key, tests[1], 1); 
                // 90% - 75% 
                (val <= limits.SD2) && (val > limits.SD1) && setParams(key, tests[2], 1); 
                // 75% - 50%
                (val <= limits.SD1) && (val > limits.SD0) && setParams(key, tests[3], 0);
                // 50% - 25% 
                (val <= limits.SD0) && (val > limits.SD1NEG) && setParams(key, tests[4], 0);
                // 25% - 10%
                (val <= limits.SD1NEG) && (val > limits.SD2NEG) && setParams(key, tests[5], 0);
                // 10% - 3%
                (val <= limits.SD2NEG) && (val > limits.SD3NEG) && setParams(key, tests[6], 1);
                // < 3%
                (val <= limits.SD3NEG) && setParams(key, tests[7], 1); 
            } else {
				setParams(key, '暂无', 3);
			}
        }

        /**
         * 单个值得判断
         * @param {*} val 
         * @param {*} limits 
         * @param {*} type 
         */
        function getSingleResult(val, limits, type) {
            if (val > limits.SD3) return type == '百分位(%)' ? '> 97%' : '> 3';
            // 97% - 90%  
            if (val <= limits.SD3 && val > limits.SD2) return type == '百分位(%)' ? '90% ~ 97%' : '2 ~ 3';
            // 90% - 75% 
            if (val <= limits.SD2 && val > limits.SD1) return type == '百分位(%)' ? '75% ~ 90%' : '1 ~ 2';
            // 75% - 50%
            if (val <= limits.SD1 && val > limits.SD0) return type == '百分位(%)' ? '50% ~ 75%' : '0 ~ 1';
            // 50% - 25% 
            if (val <= limits.SD0 && val > limits.SD1NEG) return type == '百分位(%)' ? '25% ~ 50%' : '-1 ~ 0';
            // 25% - 10%
            if (val <= limits.SD1NEG && val > limits.SD2NEG) return type == '百分位(%)' ? '10% ~ 25%' : '-2 ~ -1';
            // 10% - 3%
            if (val <= limits.SD2NEG && val > limits.SD3NEG) return type == '百分位(%)' ? '3% ~ 10%' : '-3 ~ -2';
            // < 3%
            if (val <= limits.SD3NEG) return type == '百分位(%)' ? '< 3%' : '< -3';
        }
        
        /**
         * 写入 obj 相应值
         * @param {*} key
         * @param {*} value 
         * @param {*} status 
         */
        function setParams(key, value, status) {
            obj[key + 'Res'] = value;
            obj[key + 'Status'] = status;
        }
        return obj;
    }
    //历史记录的实际测试年龄处理：
    question.testTime=function(birthday,pregnanceDay,historyObj){
        var obj=historyObj;
        for(var i=0;i<historyObj.length;i++){
            var days=this.DateDiff(birthday , historyObj[i].testTime);
            obj[i].testAge=this.getAge(days,pregnanceDay);
        }
        return obj;
    }
    //芬腾曲线：
    //儿童传入记录值数据处理：
    question.trendsNameDeal=function(data,name,trendname,color){
        var len=data.length;
        data[len-24]={
            value: data[len-24],
            label : {
                normal:{
                    show: true,
                    position: "insideRight",
                    textStyle : {
                        color:color,
                        fontSize:"9"
                    },
                    formatter:name
                }
            },
        }
        if(name=="97%" || name=="3"){
            data[len-55]={
                value: data[len-55],
                label : {
                    normal:{
                        show: true,
                        position: 'top',
                        textStyle : {
//                            color:"#aaa",
//                            fontSize:"8"
                            color:"#333",
                            fontSize:"16"
                        },
                        formatter:trendname
                    }
                },
            }
        }
        return data;
    }
    question.fentonDeal=function(data,sexColor,gender){
        var fentonRes={};
        var keyName=["weight","height","head",'baby'];
        var keyName2,lineType,lineColor;
        if(data.data.scoreType == "01"){
            keyName2=['50%','10%','90%','3%','97%','baby'];
            lineType=['solid','dashed','dashed','dotted','dotted'];
           // lineColor=['black','black','black','black','black'];
            lineColor=['#00612d','#00b0c8','#00b0c8','#ff8400','#ff8400'];
            for(var i=0;i<data.data.curvadataList.length;i++){
                if(data.data.curvadataList[i].type=='0000'+(i+1)){
                    fentonRes[keyName[i]]=[];
                    fentonRes[keyName[i]][0] = data.data.curvadataList[i].curvedata.SD0,
                    fentonRes[keyName[i]][1]=data.data.curvadataList[i].curvedata.SD2eng,
                    fentonRes[keyName[i]][2]=data.data.curvadataList[i].curvedata.SD2,
                    fentonRes[keyName[i]][3]=data.data.curvadataList[i].curvedata.SD3eng,
                    fentonRes[keyName[i]][4]=data.data.curvadataList[i].curvedata.SD3,
                    fentonRes[keyName[i]][5]=data.data.curvadataList[i].curvedata.growthrecord
                }
            }
        }else  if(data.data.scoreType == "02"){
            keyName2=['0','-1','1','-2','2','-3','3','baby'];
            lineType=['solid','solid','solid','solid','solid','solid','solid'];
            lineColor=['#00612d','#ffb13d','#ffb13d','#e41836','#e41836','#252122','#252122'];//0--SD0,1--SD1,SD1neg,2--SD2,SD2neg,3--SD3,SD3neg
            for(var i=0;i<data.data.curvadataList.length;i++){
                if(data.data.curvadataList[i].type=='0000'+(i+1)){
                    fentonRes[keyName[i]]=[];
                    fentonRes[keyName[i]][0] = data.data.curvadataList[i].curvedata.SD0,
                    fentonRes[keyName[i]][1]=data.data.curvadataList[i].curvedata.SD1eng,
                    fentonRes[keyName[i]][2]=data.data.curvadataList[i].curvedata.SD1,
                    fentonRes[keyName[i]][3]=data.data.curvadataList[i].curvedata.SD2eng,
                    fentonRes[keyName[i]][4]=data.data.curvadataList[i].curvedata.SD2,
                    fentonRes[keyName[i]][5]=data.data.curvadataList[i].curvedata.SD3eng,
                    fentonRes[keyName[i]][6]=data.data.curvadataList[i].curvedata.SD3,
                    fentonRes[keyName[i]][7]=data.data.curvadataList[i].curvedata.growthrecord
                }
            }
        }
        var series=[];
        for(var item in fentonRes){
            var name,yAxisIndex,trendName,type;
            item =='height' ? name="身长":item=='weight'? name="体重" :item=='head'?name="头围":name="baby";
            item =='height' ? trendName="身长":item=='weight'? trendName="体重" : item=='head'?trendName="头围":trendName="baby";
            item =='weight'? yAxisIndex=0:yAxisIndex=1;
            item =='weight'? type="weight":item =='height'? type="height":type="head";
            for( var i=0;i<fentonRes[item].length;i++){
                if(i==fentonRes[item].length-1){
                    var growthData={
                        'growthrecord':fentonRes[item][i],
                        'type':type,
                        'sex':gender,
                        'scoreType':data.data.scoreType,
                        'curveType':data.data.curveType
                    }
                    var babyInit=this.growthRecordDeal(growthData);
                    babyInit.nowFlag[1] =  item == "weight" ? parseFloat(babyInit.nowFlag[1]).toFixed(2) : parseFloat(babyInit.nowFlag[1]).toFixed(1);
                    var baby={};
                    baby={
                        name: name,
                        type: 'line',
                        data:babyInit.history,
                        symbol:'circle',
                        symbolSize:'6',
                        markPoint: {
                            itemStyle: {
                                normal: {
                                    color:babyInit.nowFlag[2]
                                }
                            },
                            data: [
                                {
                                    xAxis: babyInit.nowFlag[0],
                                    yAxis: babyInit.nowFlag[1]
                                }
                            ]
                        },
                        itemStyle: {
                            normal: {
                                color: sexColor,
                                lineStyle: {
                                    width:1
                                }
                            },
                            emphasis:{
                                color:sexColor
                            }
                        },
                        yAxisIndex:yAxisIndex
                    }
                    series.push(baby);
                }else{
                    fentonRes[item][i]=this.trendsNameDeal(fentonRes[item][i],keyName2[i],trendName,lineColor[i]);
                    var trend= {
                        name: keyName2[i],
                        type: 'line',
                        smooth:"true",
                        symbol:'circle',
                        hoverAnimation:false,
                        itemStyle: {
                            normal: {
                                color: "transparent",
                                lineStyle: {
                                    color:lineColor[i],
                                    type:lineType[i],
                                    width:1
                                }
                            }
                        },
                        data: fentonRes[item][i],
                        yAxisIndex:yAxisIndex
                    }
                    series.push(trend);
                }
            }
        }
        series.push({
            type: 'line',
            symbol:'none',
            hoverAnimation:false,
            itemStyle: {
                normal: {
                    lineStyle: {
                        color:"#333",
                        width:2
                    }
                }
            },
            data: [[40,-30],[40,60]],
            yAxisIndex:1
        });
        return series;
    }
    return question;
});